//
//  UIAlertViews.m
//  SelfDriving
//
//  Created by apple on 16/12/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "UIAlertViews.h"
#define ScreenWidth [UIScreen mainScreen].bounds.size.width

#define ScreenHeight [UIScreen mainScreen].bounds.size.height

@implementation UIAlertViews{
    UILabel *lable;
    UIImageView *headim;
    NSString *uid;
    LoginResponseModel *user;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = UIColorFromRGB(0xf4f3f3);
        self.layer.cornerRadius = 4;
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(self.frame.size.width - 25, 5, 20, 20)];
        [btn setImage:[UIImage imageNamed:@"图标---关闭1"] forState:UIControlStateNormal];
        btn.titleLabel.textColor = UIColorFromRGB(0x6AD8FB);
        btn.backgroundColor = [UIColor whiteColor];
        [btn addTarget:self action:@selector(hideTabelView) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        
        BaseButton *tichu = [[BaseButton alloc]initWithFrame:CGRectMake(10, 5, 50, 25)];
        [tichu setTitle:@"踢出" forState:UIControlStateNormal];
        tichu.tag = 100;
        tichu.layer.borderColor = [UIColor blackColor].CGColor;
        tichu.layer.borderWidth = 1;
        [tichu addTarget:self action:@selector(didselectBtns:) forControlEvents:UIControlEventTouchUpInside];
        tichu.titleLabel.font = [UIFont systemFontOfSize:14];
        [tichu setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [tichu setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [tichu setBackgroundColor:UIColorFromRGB(0x424141) forState:UIControlStateHighlighted];
        
        [self addSubview:tichu];
        
        headim = [[UIImageView alloc]initWithFrame:CGRectMake(10, 60, 40, 40)];
        headim.image = [UIImage imageNamed:@"notimgs"];
        headim.backgroundColor = [UIColor whiteColor];
        headim.clipsToBounds = YES;
        headim.layer.borderWidth = 1;
        headim.layer.borderColor = [UIColor whiteColor].CGColor;
        headim.layer.cornerRadius = headim.frame.size.width/2;
        [self addSubview:headim];
        
        
        lable = [[UILabel alloc]initWithFrame:CGRectMake(headim.frame.size.width + headim.frame.origin.x + 10,  headim.frame.origin.y - 10 , self.frame.size.width-60, 65)];
        lable.font = [UIFont systemFontOfSize:14];
        lable.text = @"这里是内容";
        [self addSubview:lable];
        
        
        BaseButton *hfbtn = [[BaseButton alloc]initWithFrame:CGRectMake((self.frame.size.width/2)/2-110/2, (self.frame.size.height/2)+((self.frame.size.height/2)/2), 110, 30)];
        [hfbtn setTitle:@"回复" forState:UIControlStateNormal];
        hfbtn.tag = 101;
        hfbtn.layer.borderColor = [UIColor blackColor].CGColor;
        hfbtn.layer.borderWidth = 1;
        [hfbtn addTarget:self action:@selector(didselectBtns:) forControlEvents:UIControlEventTouchUpInside];
        hfbtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [hfbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [hfbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [hfbtn setBackgroundColor:UIColorFromRGB(0x424141) forState:UIControlStateHighlighted];
        
        
        [self addSubview:hfbtn];
        
        
        BaseButton *guanzhu = [[BaseButton alloc]initWithFrame:CGRectMake(hfbtn.frame.size.width+hfbtn.frame.origin.x+((self.frame.size.width/2)/2-110/2)*2, hfbtn.frame.origin.y, hfbtn.frame.size.width, hfbtn.frame.size.height)];
        [guanzhu setTitle:@"关注" forState:UIControlStateNormal];
        guanzhu.tag = 102;
        guanzhu.layer.borderColor = [UIColor blackColor].CGColor;
        guanzhu.layer.borderWidth = 1;
        [guanzhu addTarget:self action:@selector(didselectBtns:) forControlEvents:UIControlEventTouchUpInside];
        
        [guanzhu setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [guanzhu setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [guanzhu setBackgroundColor:UIColorFromRGB(0x424141) forState:UIControlStateHighlighted];
        guanzhu.titleLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:guanzhu];
        
        self.datePickerViewBg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        self.datePickerViewBg.backgroundColor = [UIColor grayColor];
        self.datePickerViewBg.layer.opacity = 0.4;
        
        [[[[UIApplication sharedApplication] windows] firstObject] addSubview:self.datePickerViewBg];
    }
    
    return self;
}
-(void)didselectBtns:(BaseButton *)btn{
    if ([_deleagte respondsToSelector:@selector(didSelectBtn:)]) {
        btn.index = (int )uid;
        btn.model = user;
        [_deleagte didSelectBtn:btn];
    }
}
-(void)bingd:(NSString *)head content:(NSString *)content uid:(NSString *)uids mode:(LoginResponseModel *)users{
    [ValidateHelper setImage:head img:headim istoux:YES];
    lable.text = content;
    uid = uids;
    user = users;
    BaseButton *btn = (BaseButton *)[self viewWithTag:102];
    if ([user.isfriend intValue]==1 || [user.isfriend intValue]==3) {
        [btn setTitle:@"关注中" forState:UIControlStateNormal];
    }else{
        [btn setTitle:@"关注" forState:UIControlStateNormal];
    }
}
-(void)up{
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.6];//动画时间长度，单位秒，浮点数
    [self exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    self.frame = CGRectMake(self.frame.origin.x, ScreenHeight/2-self.frame.size.height/2, self.frame.size.width, self.frame.size.height);
    
    [UIView setAnimationDelegate:self];
    // 动画完毕后调用animationFinished
    [UIView setAnimationDidStopSelector:@selector(animationFinished)];
    [UIView commitAnimations];
}

-(void)down{
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.6];//动画时间长度，单位秒，浮点数
    self.frame = CGRectMake(self.frame.origin.x,ScreenHeight, self.frame.size.width, self.frame.size.height);
    [UIView setAnimationDelegate:self];
    // 动画完毕后调用animationFinished
    [UIView setAnimationDidStopSelector:@selector(animationFinished)];
    [UIView commitAnimations];
    [self.datePickerViewBg removeFromSuperview];
    [self removeFromSuperview];
    
}
-(void)animationFinished{
    NSLog(@"动画结束!");
}

-(void)hideTabelView{
    [self down];
    
    [self removeFromSuperview];
}

@end
